package com.jeeplus.test.jlnu.graduationInfo.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.test.jlnu.archivalInfo.domain.entity.ArchParmerter;
import com.jeeplus.test.jlnu.graduationInfo.domain.entity.GraduationPameter;
import com.jeeplus.test.jlnu.graduationInfo.domain.vo.GraduationInfoReqVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface GraduationInfoMapper {

    @Select({
            "<script>",
            "SELECT g.*,",
            "       ad.archival_num AS archivalNum,",
            "       ad.case_title AS caseTitle,",
            "       ad.file_title AS fileTitle,",
            "       ad.save_location AS saveLocation,",
            "       ad.page_location AS pageLocation,",
            "       ad.page_num AS pageNum,",
            "       ad.examinee_num AS examineeNum,",
            "       ad.admission_num AS admissionNum,",
            "       ad.student_id AS studentId,",
            "       ad.name AS name,",
            "       ad.gender AS gender,",
            "       ad.birthday AS birthday,",
            "       ad.political_outlook AS politicalOutlook,",
            "       ad.nation AS nation,",
            "       ad.id_card AS idCard,",
            "       ad.plan_nature AS planNature,",
            "       ad.admission_schools AS admissionSchools,",
            "       ad.admission_academy AS admissionAcademy,",
            "       ad.admission_major AS admissionMajor,",
            "       ad.admission_time AS admissionTime,",
            "       ad.gradation AS gradation,",
            "       ad.educational_system AS educationalSystem,",
            "       ad.learning_forms AS learningForms,",
            "       ad.examinee_sort AS examineeSort,",
            "       ad.batch AS batch,",
            "       ad.graduation_school AS graduationSchool,",
            "       ad.source_area AS sourceArea,",
            "       ad.area_name AS areaName,",
            "       ad.home_address AS homeAddress,",
            "       ad.postal_code AS postalCode,",
            "       ad.phone_num AS phoneNum,",
            "       ad.info_source AS infoSource,",
            "       ad.remarks AS remarks,",
            "       ad.ext1 AS ext1,",
            "       ad.ext2 AS ext2,",
            "       ad.ext3 AS ext3,",
            "       ad.ext4 AS ext4,",
            "       ad.ext5 AS ext5,",
            "       ad.ext6 AS ext6,",
            "       ad.ext7 AS ext7,",
            "       ad.ext8 AS ext8,",
            "       ad.ext9 AS ext9,",
            "       ad.ext10 AS ext10,",
            "       ad.ext11 AS ext11,",
            "       ad.ext12 AS ext12,",
            "       ad.ext13 AS ext13,",
            "       ad.ext14 AS ext14,",
            "       ad.ext15 AS ext15,",
            "       ad.ext16 AS ext16,",
            "       ad.ext17 AS ext17,",
            "       ad.ext18 AS ext18,",
            "       ad.ext19 AS ext19,",
            "       ad.ext20 AS ext20",
            "FROM jlnu_graduation_info g",
            "LEFT JOIN jlnu_admission_info ad ON g.student_id = ad.student_id",
            "WHERE 1=1",
            "<if test='graduationInfoReqVo.name != null and graduationInfoReqVo.name != \"\"'>",
            "AND ad.name = #{graduationInfoReqVo.name}",
            "</if>",
            "<if test='graduationInfoReqVo.studentId != null and graduationInfoReqVo.studentId != \"\"'>",
            "AND ad.student_id = #{graduationInfoReqVo.studentId}",
            "</if>",
            "<if test='graduationInfoReqVo.admissionAcademy != null and graduationInfoReqVo.admissionAcademy != \"\"'>",
            "AND ad.admission_academy = #{graduationInfoReqVo.admissionAcademy}",
            "</if>",
            "<if test='graduationInfoReqVo.admissionMajor != null and graduationInfoReqVo.admissionMajor != \"\"'>",
            "AND ad.admission_major = #{graduationInfoReqVo.admissionMajor}",
            "</if>",
            "<if test='graduationInfoReqVo.phoneNum != null and graduationInfoReqVo.phoneNum != \"\"'>",
            "AND ad.phone_num = #{graduationInfoReqVo.phoneNum}",
            "</if>",
            "</script>"
    })
    Page<GraduationInfoReqVo> getGraduationInfoPage(ArchParmerter graduationInfoReqVo, Page<GraduationInfoReqVo> page);
    @Select("select count(*) from jlnu_graduation_info g left join jlnu_admission_info a on g.student_id = a.student_id where a.name = #{name} and a.id_card = #{idCardNum}")
    int searchIn(String name, String idCardNum);
    @Select("SELECT a.id_card as idCardNum,a.admission_major,a.name, a.student_id, a.gender, a.nation, s.native_place, a.birthday, s.study_start_time, s.study_end_time, " +
            "a.admission_schools AS school, a.educational_system, a.gradation, g.graduation_date, g.diploma_num, " +
            "g.degree_level, g.degree_type, g.degree_certificate_num " +
            "FROM jlnu_graduation_info g " +
            "LEFT JOIN jlnu_admission_info a ON g.student_id = a.student_id " +
            "LEFT JOIN jlnu_qualification_info s ON s.student_id = g.student_id where g.student_id = #{studentId}")
    GraduationPameter selectAll(String studentId, String name);
    @Update({
            "<script>",
            "UPDATE jlnu_graduation_info",
            "<set>",
            "<if test='grade != null and grade != \"\"'>grade = #{grade},</if>",
            "<if test='classId != null and classId != \"\"'>class_id = #{classId},</if>",
            "<if test='studentId != null and studentId != \"\"'>student_id = #{studentId},</if>",
            "<if test='age != null and age != \"\"'>age = #{age},</if>",
            "<if test='schoolCode != null and schoolCode != \"\"'>school_code = #{schoolCode},</if>",
            "<if test='majorCode != null and majorCode != \"\"'>major_code = #{majorCode},</if>",
            "<if test='entranceDate != null'>entrance_date = #{entranceDate},</if>",
            "<if test='graduationDate != null'>graduation_date = #{graduationDate},</if>",
            "<if test='graduationCollege != null and graduationCollege != \"\"'>graduation_college = #{graduationCollege},</if>",
            "<if test='completionConclusion != null and completionConclusion != \"\"'>completion_conclusion = #{completionConclusion},</if>",
            "<if test='diplomaNum != null and diplomaNum != \"\"'>diploma_num = #{diplomaNum},</if>",
            "<if test='diplomaDate != null'>diploma_date = #{diplomaDate},</if>",
            "<if test='degreeLevel != null and degreeLevel != \"\"'>degree_level = #{degreeLevel},</if>",
            "<if test='degreeType != null and degreeType != \"\"'>degree_type = #{degreeType},</if>",
            "<if test='disciplineMajor != null and disciplineMajor != \"\"'>discipline_major = #{disciplineMajor},</if>",
            "<if test='supervisor != null and supervisor != \"\"'>supervisor = #{supervisor},</if>",
            "<if test='thesisTitle != null and thesisTitle != \"\"'>thesis_title = #{thesisTitle},</if>",
            "<if test='degreeCertificateNum != null and degreeCertificateNum != \"\"'>degree_certificate_num = #{degreeCertificateNum},</if>",
            "<if test='degreeCertificateDate != null'>degree_certificate_date = #{degreeCertificateDate},</if>",
            "<if test='presidentName != null and presidentName != \"\"'>president_name = #{presidentName},</if>",
            "<if test='correspondenceStation != null and correspondenceStation != \"\"'>correspondence_station = #{correspondenceStation},</if>",
            "<if test='responsiblePerson != null and responsiblePerson != \"\"'>responsible_person = #{responsiblePerson},</if>",
            "<if test='dateTime != null'>date_time = #{dateTime},</if>",
            "<if test='standards != null and standards != \"\"'>standards = #{standards},</if>",
            "<if test='quantity != null'>quantity = #{quantity},</if>",
            "<if test='pageCount != null'>page_count = #{pageCount},</if>",
            "<if test='archiveUnit != null and archiveUnit != \"\"'>archive_unit = #{archiveUnit},</if>",
            "<if test='transferor != null and transferor != \"\"'>transferor = #{transferor},</if>",
            "<if test='receiver != null and receiver != \"\"'>receiver = #{receiver},</if>",
            "<if test='transferTime != null'>transfer_time = #{transferTime},</if>",
            "</set>",
            "WHERE student_id = #{studentId}",
            "</script>"
    })
    int updateGraduation(GraduationInfoReqVo graduationInfoReqVo);

    int addGraduationInfo(GraduationInfoReqVo graduationInfoReqVo);
}
